import { getFirstAttrAPI, geThirdAttrAPI, getSecondAttrAPI } from '@/apis/attr'
import { AttrResData, cateList } from '@/types/attr'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAttrStore = defineStore('attr', () => {
  //定义数据
    const c1Id=ref<number|string>('')
    const c2Id=ref<number|string>('')
    const c3Id=ref<number|string>('')
    const firstCateList = ref<cateList>([])
    const secondCateList = ref<cateList>([])
    const thirdCateList = ref<cateList>([])
  // action方法
    // 获取一级分类方法
    const getFirstCateData = async () => {
        const res:AttrResData = await getFirstAttrAPI()
        firstCateList.value = res.data
    }

    //获取二级分类的方法
    const getSecondCateData=async(c1Id:number)=>{
        const res:AttrResData=await getSecondAttrAPI(c1Id)
        secondCateList.value=res.data        
    }
    // 获取三级分类的方法
    const getThirdCateData=async(c2Id:number)=>{
        const res=await  geThirdAttrAPI(c2Id)
        thirdCateList.value=res.data
    }


  return{
    c1Id,
    c2Id,
    c3Id,
    firstCateList,
    secondCateList,
    thirdCateList,
    getFirstCateData,
    getSecondCateData,
    getThirdCateData
  }
})
